/**
 * Copyright 2011 Mathieu Magnaudet
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package edu.enac.geoapp.gui.custom.component;

import java.awt.Insets;

import javax.swing.ImageIcon;
import javax.swing.JButton;

import edu.enac.geoapp.gui.component.Activable;

/**
 * Custom button
 * @author mathieu
 *
 */
@SuppressWarnings("serial")
public class ImageButton extends JButton implements Activable {
	private String value;
	private ImageIcon inactiveIcon;
	private ImageIcon activeIcon;
	private boolean isactive;

	public ImageButton(String path) {
		this(path,path);	
	}
	
	public ImageButton(String activeIconPath, String inactiveIconPath) {
		this.activeIcon = new ImageIcon(activeIconPath);
		this.inactiveIcon = new ImageIcon(inactiveIconPath);
		setIcon(inactiveIcon);
		setMargin(new Insets(0, 0, 0, 0));
		setIconTextGap(0);
		setBorderPainted(false);
		setBorder(null);
		setContentAreaFilled(false);
		setText(null);
		setSize(inactiveIcon.getImage().getWidth(null), inactiveIcon.getImage().getHeight(null));
		setActive(false);
	}

	/**
	 * @param value
	 *            the value to set
	 */
	public void setValue(String value) {
		this.value = value;
	}

	/**
	 * @return the value
	 */
	public String getValue() {
		return value;
	}

	/**
	 * @param inactiveIcon
	 *            the inactiveIcon to set
	 */
	public void setInactiveIcon(String inactiveIcon) {
		this.inactiveIcon = new ImageIcon(inactiveIcon);
	}

	@Override
	public boolean isActive() {
		return isactive;
	}

	@Override
	public void setActive(boolean isActive) {
		this.isactive = isActive;
		if (isactive)
			setIcon(activeIcon);
		else
			setIcon(inactiveIcon);
		
	}
}
